package utils;

import cn.hutool.core.io.FileUtil;
import cn.hutool.db.Db;
import cn.hutool.db.ds.DSFactory;
import cn.hutool.db.ds.druid.DruidDSFactory;

import javax.sql.DataSource;

/**
 * @Author: gcr
 * @Date: 2022/5/15 20:51
 */
public class DbUtils {
    public static void main(String[] args) {


    }

    public static Db getCorrect() {
        if (FileUtil.exist("D:\\我的弹琴")) {
            return getHotelLocalDb();
        } else {
            return getCompanyLocalDb();
        }
    }


    // 获取宿舍db
    public static Db getHotelLocalDb() {

        DSFactory.setCurrentDSFactory(new DruidDSFactory());
        DataSource ds = DSFactory.get("server_hotel");
        Db use = Db.use(ds);
        return use;
    }

    // 获取公司db
    public static Db getCompanyLocalDb() {
        DSFactory.setCurrentDSFactory(new DruidDSFactory());
        DataSource ds = DSFactory.get("server_local3307");
        Db use = Db.use(ds);
        return use;
    }

    // 获取服务器db
    public static Db getServerLocalDb() {
        DSFactory.setCurrentDSFactory(new DruidDSFactory());
        DataSource ds = DSFactory.get("server_server");
        Db use = Db.use(ds);
        return use;
    }
}
